Difference between <context:annotation-config> and <context:component-scan>
<context:annotation-config> |
<context:component-scan> |
---|---|
<context:annotation-config> can resolve are @Autowired, @Qualifier, @PostConstruct, @PreDestroy, and @Resource |
<context:component-scan> may identify a number of them, including @Component, @Repository, @Service, @Controller, @RestController, and @Configuration. |
In context, the beans are notregistered by the component-config. |
In context, the beans are registered by the component-scan. |
Determining beans and their dependencies is done using context:annotation-config. |
Context:component-scan is used for general-purpose component auto-detection. |
Annotations in beans that are already registered in the application context are activated using <context:annotation-config>. |
Similar to <context:annotation-config>, <context:component-scan> may likewise search packages for beans inside the application context and register them. |
Spring MVC context:annotation-config VS context:component-scan
In this article, we will learn about Spring MVC <context:annotation-config> vs <context:component-scan>. Activating all annotations existing in Java beans that have already been registered either by definition in an application context file or by component scanning is the primary function of annotation-config. The requirement for registration is crucial. The component scan assigns the Spring Bean registration to Java classes annotated with @component, @service, @repository, and other attributes. It can do all the functions that annotation config can.